package com.szyjjk.service;

import com.szyjjk.entity.*;
import com.szyjjk.mapper.*;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(readOnly = true)
public class RunMapPicService {
	@Autowired
	private RunMapPicMapper runMapPicMapper;

	/**
	 * 插入数据
	 * 
	 * @param runFilePath
	 * @return
	 */
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public void insertRunFilePath(RunMapPic runMapPic) {
		try {	
			runMapPicMapper.insert(runMapPic);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public List<RunMapPic> findFilePath(String name,String code, Date date){
		RunMapPicExample example = new RunMapPicExample();
		example.createCriteria().andMapValueEqualTo(code).andMapTimeEqualTo(date).andMapNameEqualTo(name);
		return this.runMapPicMapper.selectByExample(example);
	}
	public List<RunMapPic> findByMapName(String fileName) {
		RunMapPicExample example = new RunMapPicExample();
		example.createCriteria().andMapNameEqualTo(fileName);
		example.setOrderByClause("create_time limit 0,1");
		try {	
			List<RunMapPic> selectByExample = runMapPicMapper.selectByExample(example);
			return selectByExample;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public void delByMapName(String fileName) {
		RunMapPicExample example = new RunMapPicExample();
		example.createCriteria().andMapNameEqualTo(fileName);
		try {
			runMapPicMapper.deleteByExample(example);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public void insertRunFilePathPng(RunMapPic runMapPic) {
		try {	
			runMapPicMapper.insertPng(runMapPic);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	public List<RunMapPic> findByMapNamePng(String fileName) {
		RunMapPicExample example = new RunMapPicExample();
		example.createCriteria().andMapNameEqualTo(fileName);
		example.setOrderByClause("create_time limit 0,1");
		try {	
			List<RunMapPic> selectByExample = runMapPicMapper.selectByExamplePng(example);
			return selectByExample;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public List<RunMapPic> findByNameTimePro(String mapId,String pro,Date mapTime) {
		RunMapPicExample example = new RunMapPicExample();
		example.createCriteria().andFileidEqualTo(mapId).andMapValueEqualTo(pro).andMapTimeEqualTo(mapTime);
		example.setOrderByClause("create_time limit 0,1");
		try {
			List<RunMapPic> selectByExample = runMapPicMapper.selectByExamplePng(example);
			return selectByExample;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public void delByMapNamePng(String fileName) {
		RunMapPicExample example = new RunMapPicExample();
		example.createCriteria().andMapNameEqualTo(fileName);
		try {
			runMapPicMapper.deleteByExamplePng(example);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
}
